﻿Imports Microsoft.VisualBasic.CompilerServices
Imports System
Imports System.Reflection
Imports System.Windows.Forms
Imports SERM.IModule
Imports System.Data
Imports System.Data.Linq
Imports System.Linq



Namespace SERM
    <StandardModule()> _
    Friend NotInheritable Class PluginLoader
        ' Methods
        Public Shared Function LoadPlugIn(ByVal LoadPath As String) As ISERMModule
            Dim plugin As ISERMModule = Nothing
            Try
                Dim assembly As Assembly = assembly.LoadFrom(LoadPath)
                Dim plugs As Type = (From t In [assembly].GetTypes Where t.GetInterface("ISERMModule") IsNot Nothing Select t).FirstOrDefault()
                If plugs IsNot Nothing Then
                    plugin = DirectCast([assembly].CreateInstance(plugs.FullName), ISERMModule)
                End If
            Catch exception1 As Exception
                ProjectData.SetProjectError(exception1)
                Dim exception As Exception = exception1
                MessageBox.Show(exception.Message)
                plugin = Nothing
                ProjectData.ClearProjectError()
                Return plugin
                ProjectData.ClearProjectError()
            End Try
            Return plugin
        End Function
    End Class
End Namespace

